package com.study.debby.smarttable.util

import android.graphics.Color
import android.graphics.Paint
import com.bin.david.form.core.TableConfig
import com.bin.david.form.data.format.bg.IBackgroundFormat
import com.bin.david.form.data.style.FontStyle
import com.bin.david.form.data.style.LineStyle
import com.study.debby.smarttable.bean.UserInfo
import java.text.SimpleDateFormat
import java.util.*

/**
 * Created by debby on 2018/6/6.
 * 描述:SmartTable数据管理
 */

/**
 *新增数据
 */
fun addData(): ArrayList<UserInfo> {
    val list = ArrayList<UserInfo>()
    list.add(UserInfo(10000, "用户0", 18, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10000, "用户测试1", 18, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10001, "用户1", 19, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10002, "用户2", 20, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10003, "用户3", 21, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10004, "用户4", 22, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10005, "用户5", 23, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10006, "用户6", 24, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10006, "用户测试2", 24, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    list.add(UserInfo(10007, "用户7", 25, getToday(),
            UserInfo.Score(80, 80, 80, 80),
            UserInfo.Hobby("看书", "看电影", "听音乐",
                    UserInfo.Hobby.subHobby("英雄联盟", "沃土"))
    ))
    return list
}

/**
 * 初始化表格样式
 */
fun initConfig(config: TableConfig) {
    config.isShowXSequence = false//是否显示顶部序号列
    config.isShowYSequence = true//是否显示左侧序号列
    config.isShowTableTitle = true//是否显示标题
    config.isFixedYSequence = true//是否固定左侧序号列
    //标题字体样式
    val titleFont = FontStyle()
    titleFont.textColor = Color.rgb(13, 146, 207)
    titleFont.textSize = 60
    config.tableTitleStyle = titleFont
    //列标题字体样式
    val columnFont = FontStyle()
    columnFont.textSize = 40
    columnFont.textColor = Color.rgb(13, 146, 207)
    config.columnTitleStyle = columnFont
    //列标题网格线样式
    val columnTitleGridStyle = LineStyle()
    columnTitleGridStyle.color = Color.WHITE
    config.columnTitleGridStyle = columnTitleGridStyle
    //列标题背景样式
    config.columnTitleBackground = IBackgroundFormat { canvas, rect, paint ->
        paint.style = Paint.Style.FILL
        paint.color = Color.rgb(241, 242, 245)
        canvas!!.drawRect(rect!!.left.toFloat(),
                rect.top.toFloat(),
                rect.right.toFloat(),
                rect.bottom.toFloat(), paint)
    }
    //内容字体样式
    val contentFont = FontStyle()
    contentFont.textSize = 30
    contentFont.textColor = Color.rgb(68, 68, 68)
    config.contentStyle = contentFont
    //内容网格线样式
    val contentGridStyle = LineStyle()
    contentGridStyle.color = Color.rgb(241, 242, 245)
    config.contentGridStyle = contentGridStyle
    //内容背景样式
    config.contentBackground = IBackgroundFormat { canvas, rect, paint ->
        paint.style = Paint.Style.FILL
        paint.color = Color.WHITE
        canvas!!.drawRect(rect!!.left.toFloat(),
                rect.top.toFloat(),
                rect.right.toFloat(),
                rect.bottom.toFloat(), paint)
    }

}

private fun getToday(): String {
    val date = Date(System.currentTimeMillis())
    val sdf = SimpleDateFormat("yyyy年MM月dd日HH时mm分", Locale("zh", "CN"))
    return sdf.format(date)
}
